﻿using How2jVue.Controllers.Contexts;
using How2jVue.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace How2jVue.Controllers
{
    public class HeroController : Controller
    {
        static HeroContext _context = new HeroContext();


        // GET: Hero
        public ActionResult Index()
        {
            return View();
        }
/*

        // GET: Hero/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }

        // GET: Hero/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: Hero/Create
        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        // GET: Hero/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }

        // POST: Hero/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        // GET: Hero/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        // POST: Hero/Delete/5
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

*/
        [HttpGet]
        public JsonResult Get()
        {
            return Json(_context.Get(), JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult Add(Hero hero)
        {
            _context.Add(hero);
            return Json(_context.Get());
        }

        [HttpPost]
        public JsonResult Update(int idx, Hero hero)
        { 
            _context.Update(idx,hero);
            return Json(_context.Get());
        }

        [HttpPost]
        public JsonResult Delete(string name)
        { 
            _context.Delete(name);
            return Json(_context.Get());
        }
    }
}
